package cn.edu.sdjzu.xg23.kcsj01_backend.controller;

import cn.edu.sdjzu.xg23.kcsj01_backend.controller.*;
import cn.edu.sdjzu.xg23.kcsj01_backend.entity.LiteratureDatabase;
import cn.edu.sdjzu.xg23.kcsj01_backend.service.*;
import cn.edu.sdjzu.xg23.kcsj01_backend.utils.*;
import cn.edu.sdjzu.xg23.kcsj01_backend.entity.*;
import cn.edu.sdjzu.xg23.kcsj01_backend.mapper.*;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@RestController
public class LiteratureDatabaseController {
    @Autowired
    private LiteratureDatabaseService literatureDatabaseService;

    @GetMapping("/literatureDatabase")
    public Result get(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize,
            @RequestBody(required = false) LiteratureDatabase literatureDatabase) {

        PageInfo<LiteratureDatabase> literatureDatabasePageInfo = literatureDatabaseService.get(pageNum, pageSize, literatureDatabase);
        System.out.println(literatureDatabasePageInfo);
        return Result.success(literatureDatabasePageInfo);
    }

    @PostMapping("/literatureDatabase")
    public Result save(@RequestBody LiteratureDatabase literatureDatabase) {
        return Result.success(literatureDatabaseService.save(literatureDatabase));
    }

    @PutMapping("/literatureDatabase")
    public Result update(@RequestBody LiteratureDatabase literatureDatabase) {
        return Result.success(literatureDatabaseService.update(literatureDatabase));
    }

    @DeleteMapping("/literatureDatabase/{id}")
    public Result delete(@PathVariable long id) {
        return Result.success(literatureDatabaseService.delete(id));
    }
}
